from base.base import Base
from selenium.webdriver.common.by import By
class PageHeader(Base):
    # 登录链接
    login_link = By.PARTIAL_LINK_TEXT, "登录"
    # 注册链接
    register_link = By.PARTIAL_LINK_TEXT, "注册"
    # 安全退出链接
    loginout_link = By.PARTIAL_LINK_TEXT, "安全退出"
    # 搜索输入框
    search_input = By.CSS_SELECTOR, "#q"
    # 搜索按钮
    search_btn = By.CSS_SELECTOR, ".ecsc-search-button"
    # 导航链接
    nav_link_1 = By.CSS_SELECTOR, "#navitems > li:nth-child(2) > a"
    # 我的购物车按钮
    my_card = By.CSS_SELECTOR, ".c-n"

    def click_login_link(self):
        self.base_click(self.login_link)

    def click_register_link(self):
        self.base_click(self.register_link)

    def click_loginout_link(self):
        self.base_click(self.loginout_link)

    def input_search(self, keyword):
        self.base_input(self.input_search, keyword)

    def click_search_btn(self):
        self.base_click(self.search_btn)

    def click_nav_link_1(self):
        self.base_click(self.nav_link_1)
        # 切换窗口
        self.base_switch_to_window("商品列表")

    def click_my_card(self):
        self.base_click(self.my_card)

    # 组合搜索功能
    def search(self, keyword):
        self.input_search(keyword)
        self.click_search_btn()


